﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoCAD;

namespace CADAutoPlot
{
    class DrawComponementsByRandomParams
    {
        private Dictionary<string, Object> windowData;
        private AcadModelSpace modelSpace;
        private Preview previewImg;
        private int type;
        private int count = 0;
        private double ɛ = 0.1;
        private Dictionary<int, Array> tmp;

        //初始化数据
        internal double upperLBoardLength;
        internal double leftLBoardLength;
        internal double rightLBoardLength;

        internal double upperLBoardWidth;
        internal double upperLBoardHeight;
        internal double upperBoardLength;
        internal double lowerBoardLength;

        internal double bladeLength;
        internal double invisPullRod1Length;
        internal double upperBoardWidth;
        internal double lowerBoardWidth;
        internal double bladeWidth;
        internal double invisPullRod1Width;

        internal double upperBoardHeight;
        internal double lowerBoardHeight;
        internal double bladeHeight;
        internal double invisPullRod1Height;

        internal double lboardSlotWidth;
        internal double lboardSlotDept;

        internal double lboardLHeight;

        internal double boardLength;
        internal double boardWidth;
        internal double boardHeight;
        internal double boardSlotWidth;
        internal double boardSlotDept;

        internal double plainEdgeLength;
        internal double hidePlainEdgeLength;
        internal double hideCoverEdgeLength;
        internal double plainCoverEdgeLength;

        internal double plainEdgeWidth;
        internal double hidePlainEdgeWidth;

        internal double plainEdgeHeight;
        internal double hidePlainEdgeHeight;

        //补充
        internal double plainCoverEdgeWidth;
        internal double hideCoverEdgeWidth;

        internal double plainCoverEdgeHeight;
        internal double hideCoverEdgeHeight;

        internal double hidePlainEdgeSlotWidth;

        internal double hidePlainEdgeSlotDept;
        internal double hideCoverEdgeCoverMaxWidth;
        internal double hideCoverEdgeCoverMaxHeight;

        internal double plainCoverEdgeCoverMaxWidth;
        internal double plainCoverEdgeCoverMaxHeight;

        //20250325
        internal double HideCoverEdgerCoverWidth;
        internal double PlainCoverEdgerCoverWidth;
        //20250813
        internal double hingeWidth;
        internal double hingeHeight;
        //20250814
        internal double windowGap;
        internal double lboardLHeight2;
        //20250815
        internal double hingeUpDis1;
        internal double hingeUpDis2;
        internal double hingeUpDis3;

        internal double[] hingeUpDis;

        internal double hingeDownDis1;
        internal double hingeDownDis2;
        internal double hingeDownDis3;

        internal double[] hingeDownDis;

        internal double[] hingeMiddleDis;

        internal double hingeNum;
        //20250827
        internal double tbarMinWidth;
        internal double tbarMaxWidth;
        internal double tbarHeight;
        internal double tbarCornerHeight;
        internal double tbarLength;
        internal double tbarLeftPos;

        internal double[] tbarPos;

        //20250828
        internal double windowWidth1;
        internal double windowWidth2;

        internal double[] windowWidth;
        //20250902
        internal double tbarRightPos;
        //
        //20250916
        internal int isWindow1Part;
        internal int isWindow2Part;
        internal int isWindow3Part;

        internal int[] isWindowsPart;

        internal int window1UpperArea;
        internal int window2UpperArea;
        internal int window3UpperArea;

        internal int[] wndUpperArea;

        internal int window1LowerArea;
        internal int window2LowerArea;
        internal int window3LowerArea;

        internal int[] wndLowerArea;

        internal int[] windowEdge;
        
        //
        internal int windowNum;
        internal int bladeNum;

        public DrawComponementsByRandomParams(AcadModelSpace space, int type, Dictionary<string, Object> data, Preview previewImg)
        {
            this.modelSpace = space;
            this.windowData = data;
            this.previewImg = previewImg;
            this.type = type;
            Console.WriteLine("DrawComponementsByRandomParams Loaded");
            //初始化数据
            upperLBoardLength = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_UPPER_LBOARD_LENGTH"));
            leftLBoardLength = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_LEFT_LBOARD_LENGTH"));
            rightLBoardLength = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_RIGHT_LBOARD_LENGTH"));
            upperLBoardWidth = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_UPPER_LBOARD_WIDTH"));
            upperLBoardHeight = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_UPPER_LBOARD_HEIGHT"));
            upperBoardLength = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_UPPER_BOARD_LENGTH"));
            lowerBoardLength = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_LOWER_BOARD_LENGTH"));
            bladeLength = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_BLADE_LENGTH"));
            invisPullRod1Length = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_INVIS_PULL_ROD1_LENGTH"));
            upperBoardWidth = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_UPPER_BOARD_WIDTH"));
            lowerBoardWidth = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_LOWER_BOARD_WIDTH"));
            bladeWidth = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_BLADE_WIDTH"));
            invisPullRod1Width = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_INVIS_PULL_ROD1_WIDTH"));
            upperBoardHeight = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_UPPER_BOARD_HEIGHT"));
            lowerBoardHeight = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_LOWER_BOARD_HEIGHT"));
            bladeHeight = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_BLADE_HEIGHT"));
            invisPullRod1Height = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_INVIS_PULL_ROD1_HEIGHT"));
            lboardSlotWidth = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_LBOARD_SLOT_WIDTH"));
            lboardSlotDept = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_LBOARD_SLOT_DEPT"));
            lboardLHeight = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_LBOARD_LHEIGHT")); //10
            boardLength = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_UPPER_BOARD_LENGTH"));
            boardWidth = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_UPPER_BOARD_WIDTH"));
            boardHeight = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_UPPER_BOARD_HEIGHT"));
            boardSlotWidth = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_UPPER_BOARD_SLOT_WIDTH"));
            boardSlotDept = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_UPPER_BOARD_SLOT_DEPT"));
            Console.WriteLine("DrawComponementsByRandomParams Loaded1");

            //1
            plainEdgeLength = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_PLAIN_EDGE_LENGTH"));
            hidePlainEdgeLength = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_HIDE_PLAIN_EDGE_LENGTH"));
            hideCoverEdgeLength = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_HIDE_COVER_EDGE_LENGTH"));
            plainCoverEdgeLength = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_PLAIN_COVER_EDGE_LENGTH"));
            plainEdgeWidth = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_PLAIN_EDGE_WIDTH"));
            hidePlainEdgeWidth = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_HIDE_PLAIN_EDGE_WIDTH"));
            plainEdgeHeight = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_PLAIN_EDGE_HEIGHT"));
            hidePlainEdgeHeight = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_HIDE_PLAIN_EDGE_HEIGHT"));
            //补充
            plainCoverEdgeWidth = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_PLAIN_COVER_EDGE_WIDTH"));
            hideCoverEdgeWidth = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_HIDE_COVER_EDGE_WIDTH"));
            plainCoverEdgeHeight = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_PLAIN_COVER_EDGE_HEIGHT"));
            hideCoverEdgeHeight = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_HIDE_COVER_EDGE_HEIGHT"));
            hidePlainEdgeSlotWidth = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_HIDE_PLAIN_EDGE_SLOT_WIDTH"));
            hidePlainEdgeSlotDept = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_HIDE_PLAIN_EDGE_SLOT_DEPT"));
            hideCoverEdgeCoverMaxWidth = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_HIDE_COVER_EDGE_COVER_MAX_WIDTH"));
            hideCoverEdgeCoverMaxHeight = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_HIDE_COVER_EDGE_COVER_MAX_HEIGHT"));
            plainCoverEdgeCoverMaxWidth = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_PLAIN_COVER_EDGE_COVER_MAX_WIDTH"));
            plainCoverEdgeCoverMaxHeight = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_PLAIN_COVER_EDGE_COVER_MAX_HEIGHT"));
            //20250325
            HideCoverEdgerCoverWidth = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_HIDE_COVER_EDGE_COVER_WIDTH"));
            PlainCoverEdgerCoverWidth = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_PLAIN_COVER_EDGE_COVER_WIDTH"));
            //20250813
            hingeWidth = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_HINGE_WIDTH"));
            hingeHeight = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_HINGE_HEIGHT"));
            //20250814
            windowGap = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_WINDOW_GAP"));
            lboardLHeight2 = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_LBOARD_LHEIGHT2"));
            Console.WriteLine("DrawComponementsByRandomParams Loaded2");
            //20250815
            /*
            tmp = Common.getObjectMap(Convert.ToString(Common.GetObjectValuesForKey(windowData, "IDC_UP_HINGE_DIS")));
            count = 0;
            hingeUpDis = new double[tmp.Count];
            foreach (Array v in tmp.Values)
            {
                hingeUpDis[count] = Convert.ToDouble(v.GetValue(0));
                ++count;
            }
            tmp = Common.getObjectMap(Convert.ToString(Common.GetObjectValuesForKey(windowData, "IDC_DOWN_HINGE_DIS")));
            count = 0;
            hingeDownDis = new double[tmp.Count];
            foreach (Array v in tmp.Values)
            {
                hingeDownDis[count] = Convert.ToDouble(v.GetValue(0));
                ++count;
            }
            */
            tmp = Common.getObjectMap(Convert.ToString(Common.GetObjectValuesForKey(windowData, "IDC_MIDDLE_HINGE_DIS")));
            count = 0;
            hingeMiddleDis = new double[tmp.Count];
            foreach (Array v in tmp.Values)
            {
                hingeMiddleDis[count] = Convert.ToDouble(v.GetValue(0));
                ++count;
            }

            Console.WriteLine("DrawComponementsByRandomParams Loaded3");

            //20250815
            hingeNum = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_HINGE_NUM"));
            //20250827
            tbarMaxWidth = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_T_BAR_MAX_WIDTH"));
            tbarMinWidth = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_T_BAR_MIN_WIDTH"));
            tbarHeight = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_T_BAR_HEIGHT"));
            tbarCornerHeight = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_T_BAR_CORNER_HEIGHT"));
            tbarLength = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_T_BAR_LENGTH"));
            //20250828
            tmp = Common.getObjectMap(Convert.ToString(Common.GetObjectValuesForKey(windowData, "IDC_T_BAR_POS")));
            count = 0;
            tbarPos = new double[tmp.Count];
            foreach (Array v in tmp.Values)
            {
                tbarPos[count] = Convert.ToDouble(v.GetValue(0));
                ++count;
            }

            //tbarLeftPos = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_T_BAR_LEFT_POS"));

            tmp = Common.getObjectMap(Convert.ToString(Common.GetObjectValuesForKey(windowData, "IDC_WINDOW_WIDTH")));
            count = 0;
            windowWidth = new double[tmp.Count];
            foreach (Array v in tmp.Values)
            {
                windowWidth[count] = Convert.ToDouble(v.GetValue(0));
                ++count;
            }

            Console.WriteLine("DrawComponementsByRandomParams Loaded4");
            //20250902
            //tbarRightPos = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_T_BAR_RIGHT_POS"));
            //20250916

            tmp = Common.getObjectMap(Convert.ToString(Common.GetObjectValuesForKey(windowData, "IDC_WINDOW_EDGE")));
            count = 0;
            windowEdge = new int[tmp.Count];
            foreach (Array v in tmp.Values)
            {
                windowEdge[count] = Convert.ToInt16(v.GetValue(0));
                ++count;
            }

            tmp = Common.getObjectMap(Convert.ToString(Common.GetObjectValuesForKey(windowData, "IDC_WINDOW_PART")));
            count = 0;
            isWindowsPart = new int[tmp.Count];
            foreach (Array v in tmp.Values)
            {
                isWindowsPart[count] = Convert.ToInt16(v.GetValue(0));
                ++count;
            }

            tmp = Common.getObjectMap(Convert.ToString(Common.GetObjectValuesForKey(windowData, "IDC_WINDOW_AREA")));
            count = 0;
            wndUpperArea = new int[tmp.Count / 2];
            wndLowerArea = new int[tmp.Count / 2];
            int upperCount = 0;
            int lowerCount = 0;
            foreach (Array v in tmp.Values)
            {
                if(count % 2 ==0)
                {
                    wndUpperArea[upperCount++] = Convert.ToInt16(v.GetValue(0));
                }
                else
                {
                    wndLowerArea[lowerCount++] = Convert.ToInt16(v.GetValue(0));
                }
                
                ++count;
            }
            Console.WriteLine("DrawComponementsByRandomParams Loaded5");
            //
            windowNum = (int)Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_WINDOW_NUM"));
            //windowWidth = Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_WINDOW_WIDTH"));
            bladeNum = (int)Convert.ToDouble(Common.GetObjectValuesForKey(windowData, "IDC_BLADE_NUM"));
        }

        //画L槽框
        public void DrawLBoard(Point startPoint, int view,bool withTBar)
        {
            int pos = 1;
            double[] LBoardStartPoints, LBoardEndPoints;
            double[] LBoardStartPoints1, LBoardEndPoints1;
            double[] LBoardStartPoints2, LBoardEndPoints2;
            double[] LBoardStartPoints3, LBoardEndPoints3;
            double[] TBoardPoints, TBoardPoints1, TBoardStartPoint, TBoardStartPoint1;
            double[] textPos, textPos1, textPos2;

            AcadPolyline UpBoard, DownBoard, LeftBoard, RightBoard, TBoard, TBoard1;

            switch (view)
            {
                case 0:
                    //画轮廓线
                    //画左
                    LBoardStartPoints = DrawDoubleLSlot(startPoint, 0, 1);
                    LeftBoard = modelSpace.AddPolyline(LBoardStartPoints);
                    LeftBoard.Closed = true;
                    previewImg.AddPolyLine(LBoardStartPoints);

                    //画窗线1
                    LBoardStartPoints1 = new double[] { startPoint.getX(), startPoint.getY(), startPoint.getZ() };
                    LBoardEndPoints1 = new double[] { startPoint.getX() + upperLBoardLength, startPoint.getY(), startPoint.getZ() };
                    modelSpace.AddLine(LBoardStartPoints1, LBoardEndPoints1);
                    previewImg.AddLine(LBoardStartPoints1, LBoardEndPoints1);
                    
                    //画右
                    LBoardStartPoints3 = DrawDoubleLSlot(new Point(startPoint.getX() + upperLBoardLength, startPoint.getY(), startPoint.getZ()), 0, -1);
                    RightBoard = modelSpace.AddPolyline(LBoardStartPoints3);
                    RightBoard.Closed = true;
                    previewImg.AddPolyLine(LBoardStartPoints3);
                    //尺寸标注
                    textPos = new double[] { (LBoardEndPoints1[0] + LBoardEndPoints1[0]) / 2, LBoardEndPoints1[1] + 45, 0 };
                    AcadDimAligned aligned = modelSpace.AddDimAligned(LBoardStartPoints1, LBoardEndPoints1, textPos);
                    aligned.TextHeight = 10;
                    aligned.Update();

                    //画窗线2
                    if (!withTBar)
                    {
                        LBoardStartPoints2 = new double[] { startPoint.getX() + upperLBoardWidth, startPoint.getY() - lboardLHeight, startPoint.getZ() };
                        LBoardEndPoints2 = new double[] { startPoint.getX() + (upperLBoardLength - upperLBoardWidth), startPoint.getY() - lboardLHeight, startPoint.getZ() };
                        modelSpace.AddLine(LBoardStartPoints2, LBoardEndPoints2);
                        previewImg.AddLine(LBoardStartPoints2, LBoardEndPoints2);
                    }
                    else
                    {
                        for (int i = 0; i < tbarPos.Length; i++)
                        {
                            //画T柱
                            TBoardStartPoint = new double[] { startPoint.getX() + tbarPos[i], startPoint.getY(), startPoint.getZ() };
                            TBoardPoints = DrawTBar(new Point(TBoardStartPoint[0] - (tbarMaxWidth / 2), TBoardStartPoint[1], TBoardStartPoint[2]), 0);

                            TBoard = modelSpace.AddPolyline(TBoardPoints);
                            TBoard.Closed = true;
                            previewImg.AddPolyLine(TBoardPoints);
                            //尺寸标注
                            textPos1 = new double[] { (LBoardEndPoints1[0] + TBoardStartPoint[0]) / 2, LBoardEndPoints1[1] + 15 + i * 5, 0 };
                            AcadDimAligned aligned2 = modelSpace.AddDimAligned(LBoardStartPoints1, TBoardStartPoint, textPos);
                            aligned2.TextHeight = 10;
                            aligned2.Update();
                            if (i == 0)
                            {
                                //画线
                                LBoardStartPoints2 = new double[] { startPoint.getX() + upperLBoardWidth, startPoint.getY() - lboardLHeight, startPoint.getZ() };
                                LBoardEndPoints2 = new double[] { startPoint.getX() + tbarPos[i] - ((tbarMinWidth) / 2), startPoint.getY() - lboardLHeight, startPoint.getZ() };
                                modelSpace.AddLine(LBoardStartPoints2, LBoardEndPoints2);
                                previewImg.AddLine(LBoardStartPoints2, LBoardEndPoints2);
                            }
                            else if(i == tbarPos.Length - 1)
                            {
                                //画线
                                LBoardStartPoints2 = new double[] { startPoint.getX() + tbarPos[i] + ((tbarMinWidth) / 2), startPoint.getY() - lboardLHeight, startPoint.getZ() };
                                LBoardEndPoints2 = new double[] { startPoint.getX() + tbarPos[i] - ((tbarMinWidth) / 2), startPoint.getY() - lboardLHeight, startPoint.getZ() };
                                modelSpace.AddLine(LBoardStartPoints2, LBoardEndPoints2);
                                previewImg.AddLine(LBoardStartPoints2, LBoardEndPoints2);
                            }
                            else
                            {
                                //画线
                                LBoardStartPoints2 = new double[] { startPoint.getX() + tbarPos[i-1] + ((tbarMinWidth) / 2), startPoint.getY() - lboardLHeight, startPoint.getZ() };
                                LBoardEndPoints2 = new double[] { startPoint.getX() + (upperLBoardLength - upperLBoardWidth), startPoint.getY() - lboardLHeight, startPoint.getZ() };
                                modelSpace.AddLine(LBoardStartPoints2, LBoardEndPoints2);
                                previewImg.AddLine(LBoardStartPoints2, LBoardEndPoints2);
                            }
                        }

                    }
                    break;
                case 1:
                    //画上框
                    LBoardStartPoints = new double[]{
                          startPoint.getX(),startPoint.getY(),startPoint.getZ(),//1
                          startPoint.getX() + upperLBoardLength,startPoint.getY(),startPoint.getZ(),//2
                          startPoint.getX() + upperLBoardLength - lboardLHeight2,startPoint.getY() - lboardLHeight2,startPoint.getZ(),//3
                          startPoint.getX() + lboardLHeight2,startPoint.getY() - lboardLHeight2,startPoint.getZ() //4
                    };
                    UpBoard = modelSpace.AddPolyline(LBoardStartPoints);
                    UpBoard.Closed = true;
                    previewImg.AddPolyLine(LBoardStartPoints);
                    //画左框
                    LBoardStartPoints1 = new double[]{
                         startPoint.getX(),startPoint.getY(),startPoint.getZ(),//1
                         startPoint.getX(),startPoint.getY() - leftLBoardLength,startPoint.getZ(),//2
                         startPoint.getX() + lboardLHeight2,windowNum <= 1 ? startPoint.getY() - leftLBoardLength:startPoint.getY() - (leftLBoardLength - lboardLHeight2),startPoint.getZ(),//3
                         startPoint.getX() + lboardLHeight2,startPoint.getY() - lboardLHeight2,startPoint.getZ() //4
                    };
                    LeftBoard = modelSpace.AddPolyline(LBoardStartPoints1);
                    LeftBoard.Closed = true;
                    previewImg.AddPolyLine(LBoardStartPoints1);
                    //画右框
                    LBoardStartPoints2 = new double[]
                    {
                         startPoint.getX() + upperLBoardLength,startPoint.getY(),startPoint.getZ(),//1
                         startPoint.getX() + upperLBoardLength,startPoint.getY() - rightLBoardLength,startPoint.getZ(),//2
                         startPoint.getX() + upperLBoardLength - lboardLHeight2,windowNum <=1 ? startPoint.getY() - rightLBoardLength :  startPoint.getY() - (rightLBoardLength - lboardLHeight2),startPoint.getZ(),//3
                         startPoint.getX() + upperLBoardLength - lboardLHeight2,startPoint.getY() - lboardLHeight2,startPoint.getZ() //4
                    };
                    RightBoard = modelSpace.AddPolyline(LBoardStartPoints2);
                    RightBoard.Closed = true;
                    previewImg.AddPolyLine(LBoardStartPoints2);
                    //窗户数量大于1时，有下框
                    if (windowNum > 1)
                    {
                        LBoardStartPoints3 = new double[]
                        {
                            startPoint.getX() + lboardLHeight2,startPoint.getY() - (leftLBoardLength - lboardLHeight2),startPoint.getZ(),//1
                            startPoint.getX() + upperLBoardLength - lboardLHeight2,startPoint.getY() - (rightLBoardLength - lboardLHeight2),startPoint.getZ(),//2
                            startPoint.getX() + upperLBoardLength,startPoint.getY() - rightLBoardLength,startPoint.getZ(),//3
                            startPoint.getX(),startPoint.getY() - leftLBoardLength,startPoint.getZ() //4
                        };
                        DownBoard = modelSpace.AddPolyline(LBoardStartPoints3);
                        DownBoard.Closed = true;
                        previewImg.AddPolyLine(LBoardStartPoints3);
                        if (withTBar)
                        {
                            for (int i = 0; i < tbarPos.Length; i++)
                            {
                                TBoardPoints = DrawTBar(new Point(startPoint.getX() + tbarPos[i] - (tbarMinWidth / 2), startPoint.getY() - lboardLHeight2, startPoint.getZ()), 1);
                                TBoard = modelSpace.AddPolyline(TBoardPoints);
                                TBoard.Closed = true;
                                previewImg.AddPolyLine(TBoardPoints);
                            }
                        }
                    }

                    //尺寸标注
                    textPos = new double[] { (startPoint.getX() + startPoint.getX() + upperLBoardLength) / 2, startPoint.getY() + 25, 0 };
                    AcadDimAligned aligned1 = modelSpace.AddDimAligned(new double[] { startPoint.getX(), startPoint.getY(), startPoint.getZ() }, new double[] { startPoint.getX() + upperLBoardLength, startPoint.getY(), startPoint.getZ() }, textPos);
                    aligned1.TextHeight = 10;
                    aligned1.Update();
                    break;
                case 2:
                    if (windowNum <= 1)
                    {
                        pos = 1;
                        LBoardStartPoints = DrawDoubleLSlot(startPoint, 2, 1);
                        UpBoard = modelSpace.AddPolyline(LBoardStartPoints);
                        UpBoard.Closed = true;
                        previewImg.AddPolyLine(LBoardStartPoints);
                        //画线1
                        LBoardStartPoints = new double[] { startPoint.getX(), startPoint.getY(), startPoint.getZ() };
                        LBoardEndPoints = new double[] { startPoint.getX(), startPoint.getY() - leftLBoardLength, startPoint.getY() };
                        modelSpace.AddLine(LBoardStartPoints, LBoardEndPoints);
                        previewImg.AddLine(LBoardStartPoints, LBoardEndPoints);
                        //画线2
                        LBoardStartPoints1 = new double[] { startPoint.getX() + lboardLHeight, startPoint.getY() - upperLBoardWidth, startPoint.getY() };
                        LBoardEndPoints1 = new double[] { startPoint.getX() + lboardLHeight, startPoint.getY() - leftLBoardLength, startPoint.getY() };
                        modelSpace.AddLine(LBoardStartPoints1, LBoardEndPoints1);
                        previewImg.AddLine(LBoardStartPoints1, LBoardEndPoints1);
                        //画线3
                        LBoardStartPoints2 = new double[] { startPoint.getX(), startPoint.getY() - leftLBoardLength, startPoint.getZ() };
                        LBoardEndPoints2 = new double[] { startPoint.getX() + lboardLHeight, startPoint.getY() - leftLBoardLength, startPoint.getZ() };
                        modelSpace.AddLine(LBoardStartPoints2, LBoardEndPoints2);
                        previewImg.AddLine(LBoardStartPoints2, LBoardEndPoints2);
                    }
                    else
                    {
                        pos = 1;
                        LBoardStartPoints = DrawDoubleLSlot(startPoint, 2, pos);
                        UpBoard = modelSpace.AddPolyline(LBoardStartPoints);
                        UpBoard.Closed = true;
                        previewImg.AddPolyLine(LBoardStartPoints);
                        //
                        pos = -1 * pos;
                        startPoint = new Point(startPoint.getX(), startPoint.getY() - leftLBoardLength, startPoint.getZ());
                        LBoardStartPoints1 = DrawDoubleLSlot(startPoint, 2, pos);
                        DownBoard = modelSpace.AddPolyline(LBoardStartPoints1);
                        DownBoard.Closed = true;
                        previewImg.AddPolyLine(LBoardStartPoints1);
                        //
                        //画线1
                        LBoardStartPoints2 = new double[] { startPoint.getX(), startPoint.getY(), startPoint.getZ() };
                        LBoardEndPoints2 = new double[] { startPoint.getX(), startPoint.getY() + leftLBoardLength, startPoint.getZ() };
                        modelSpace.AddLine(LBoardStartPoints2, LBoardEndPoints2);
                        previewImg.AddLine(LBoardStartPoints2, LBoardEndPoints2);
                        //画线2
                        LBoardStartPoints3 = new double[] { startPoint.getX() + lboardLHeight, startPoint.getY() + lboardLHeight2, startPoint.getZ() };
                        LBoardEndPoints3 = new double[] { startPoint.getX() + lboardLHeight, startPoint.getY() + lboardLHeight2 + hidePlainEdgeLength, startPoint.getZ() };
                        modelSpace.AddLine(LBoardStartPoints3, LBoardEndPoints3);
                        previewImg.AddLine(LBoardStartPoints3, LBoardEndPoints3);
                    }

                    //尺寸标注
                    textPos = new double[] { startPoint.getX() - 35, (startPoint.getY() + startPoint.getY() - pos * leftLBoardLength) / 2, 0 };
                    AcadDimRotated aligned3 = modelSpace.AddDimRotated(new double[] { startPoint.getX(), startPoint.getY(), startPoint.getZ() }, new double[] { startPoint.getX(), startPoint.getY() - pos * leftLBoardLength, startPoint.getY() }, textPos, Math.PI / 2);
                    aligned3.TextHeight = 10;
                    aligned3.Update();
                    break;
            }
        }

        public void DrawEdge(Point startPoint, int view, bool withTBar, string openType)
        {
            int pos = 1;
            double[] edgeStartPoints, edgeEndPoints, edgeStartPoints1, edgeEndPoints1, edgeStartPoints2, edgeEndPoints2, edgeStartPoints3, edgeEndPoints3, edgeStartPoints4, edgeEndPoints4, edgeStartPoints5, edgeEndPoints5, edgeStartPoints6, edgeEndPoints6, edgeStartPoints7, edgeEndPoints7, edgeStartPoints8, textPos;
            AcadPolyline edge, edge1, edge2, edge3, edge4, edge5;
            Point tmpPoint;
            double xOffset = 0;
            //足够小的一个数

            switch (view)
            {
                case 0:
                    pos = 1;
                    for(int i = 0;i < windowEdge.Length;i++)
                    {
                        
                        Console.WriteLine(i);
                        Console.WriteLine(windowEdge[i]);
                        Console.WriteLine("=======");
                        //求幂,根据pos=1或-1来判断是左侧的门边还是右侧的门边
                        pos = Convert.ToInt16(Math.Pow(-1,Convert.ToDouble(i)));
                        if(pos == -1)
                        {
                            xOffset += windowWidth[i / 2] + getEdgeWidth(windowEdge[i]);
                            tmpPoint = new Point(startPoint.getX() + xOffset, startPoint.getY(), startPoint.getZ());
                            edgeStartPoints = DrawSingleEdge(tmpPoint, 0, pos, windowEdge[i]);

                            //恢复原位
                            xOffset -= (getEdgeWidth(windowEdge[i]));

                            //画窗户
                            //画线上(窗户)
                            edgeStartPoints1 = new double[] { startPoint.getX() + xOffset, startPoint.getY() - (hidePlainEdgeHeight - hidePlainEdgeSlotWidth) / 2.0, startPoint.getZ() };
                            edgeEndPoints1 = new double[] { startPoint.getX() + xOffset - windowWidth[i / 2]  , startPoint.getY() - (hidePlainEdgeHeight - hidePlainEdgeSlotWidth) / 2.0, startPoint.getZ() };
                            modelSpace.AddLine(edgeStartPoints1, edgeEndPoints1);
                            previewImg.AddLine(edgeStartPoints1, edgeEndPoints1);
                            //画线下(窗户)
                            edgeStartPoints2 = new double[] { startPoint.getX() + xOffset, startPoint.getY() - (hidePlainEdgeHeight + hidePlainEdgeSlotWidth) / 2.0, startPoint.getZ() };
                            edgeEndPoints2 = new double[] { startPoint.getX() + xOffset - windowWidth[i / 2], startPoint.getY() - (hidePlainEdgeHeight + hidePlainEdgeSlotWidth) / 2.0, startPoint.getZ() };
                            modelSpace.AddLine(edgeStartPoints2, edgeEndPoints2);
                            previewImg.AddLine(edgeStartPoints2, edgeEndPoints2);

                            
                            //画门边尺寸标注
                            //窗户尺寸标注
                            textPos = new double[] { (edgeStartPoints2[0] + edgeEndPoints2[0]) / 2, edgeStartPoints1[1] - 35, 0 };
                            AcadDimAligned aligned1 = modelSpace.AddDimAligned(new double[] { edgeEndPoints2[0], edgeEndPoints2[1], edgeEndPoints2[2] }, new double[] { edgeStartPoints2[0], edgeStartPoints2[1], edgeStartPoints2[2] }, textPos);
                            aligned1.TextHeight = 10;
                            aligned1.Update();
                            //窗框尺寸标注
                            textPos = new double[] { (edgeEndPoints2[0] - getEdgeWidth(windowEdge[i - 1]) + edgeStartPoints2[0] + getEdgeWidth(windowEdge[i])) / 2, edgeStartPoints2[1] - 45, 0 };
                            AcadDimAligned aligned2 = modelSpace.AddDimAligned(new double[] { edgeEndPoints2[0] - getEdgeWidth(windowEdge[i - 1]), edgeEndPoints2[1], edgeEndPoints2[2] }, new double[] { edgeStartPoints2[0] + getEdgeWidth(windowEdge[i]), edgeStartPoints2[1], edgeStartPoints2[2] }, textPos);
                            aligned2.TextHeight = 10;
                            aligned2.Update();
                            

                        }
                        else
                        {
                            if(i > 0)
                            {
                                //判断有无T柱
                                if (withTBar)
                                {
                                    for (int j = 0; j < tbarPos.Length; j++)
                                    {
                                        //计算带T柱后与原点的偏移
                                        if (Math.Abs(xOffset - (tbarPos[j] - (tbarMinWidth / 2) - windowGap - lboardLHeight2)) < ɛ) 
                                        {
                                            xOffset += tbarMinWidth + 2* windowGap;
                                        }
                                    }
                                }
                                else
                                {
                                    xOffset += windowGap;
                                }
                            }
                            tmpPoint = new Point(startPoint.getX() + xOffset, startPoint.getY(), startPoint.getZ());
                            edgeStartPoints = DrawSingleEdge(tmpPoint, 0, pos, windowEdge[i]);
                        }

                        edge = modelSpace.AddPolyline(edgeStartPoints);
                        edge.Closed = true;
                        previewImg.AddPolyLine(edgeStartPoints);

                        //偏移加门边宽度
                        xOffset += getEdgeWidth(windowEdge[i]);
                    }
                    
                    break;
                case 1:
                    pos = 1;
                    for (int i = 0; i < windowEdge.Length; i++)
                    {
                        char opType = openType[i / 2];
                        pos = Convert.ToInt16(Math.Pow(-1, Convert.ToDouble(i)));
                        if (pos == -1)
                        {
                            xOffset += windowWidth[i / 2] + getEdgeWidth(windowEdge[i]);
                            if(opType == 'R')
                            {
                                DrawHinge(new Point(startPoint.getX() + xOffset, startPoint.getY(), startPoint.getZ()), 1, i / 2, pos);
                            }
                            edgeStartPoints = DrawSingleEdge(new Point(startPoint.getX() + xOffset, startPoint.getY(), startPoint.getZ()), 1, pos, windowEdge[i]);
                            xOffset -= getEdgeWidth(windowEdge[i]);
                        }
                        else
                        {
                            if (withTBar)
                            {
                                for (int j = 0; j < tbarPos.Length; j++)
                                {
                                    //计算带T柱后与原点的偏移
                                    if (Math.Abs(xOffset - (tbarPos[j] - (tbarMinWidth / 2) - windowGap - lboardLHeight2)) < ɛ)
                                    {
                                        xOffset += tbarMinWidth + 2 * windowGap;
                                    }
                                }
                            }
                            else
                            {
                                xOffset += windowGap;
                            }
                            if (opType == 'L')
                            {
                                DrawHinge(new Point(startPoint.getX() + xOffset, startPoint.getY(), startPoint.getZ()), 1, i / 2, pos);
                            }
                            edgeStartPoints = DrawSingleEdge(new Point(startPoint.getX() + xOffset, startPoint.getY(), startPoint.getZ()), 1, pos, windowEdge[i]);
                        }
                        
                        edge = modelSpace.AddPolyline(edgeStartPoints);
                        edge.Closed = true;
                        previewImg.AddPolyLine(edgeStartPoints);
                        xOffset += getEdgeWidth(windowEdge[i]);

                    }

                    break;
                case 2:
                    break;
            }
        }

        //画上下固定板
        public void DrawBoard(Point startPoint, int view,bool withTBar)
        {
            int pos = -1;
            double[] edgeStartPoints, edgeEndPoints, textPos;
            double xOffset, yOffset;
            AcadPolyline edge, edge1;

            double singleBladeWidth = (upperLBoardLength - (boardSlotDept * 2)) / (bladeNum / windowNum);
            //y_offset = (int)((bladeNum / windowNum) * singleBladeWidth);

            switch (view)
            {
                case 0:
                    break;
                case 1:
                    xOffset = 0;
                    for(int i = 0;i < windowNum;i++)
                    {
                        pos = Convert.ToInt16(Math.Pow(-1, Convert.ToDouble(i)));
                        yOffset = hidePlainEdgeLength - lowerBoardWidth;
                        if(i > 0)
                        {
                            xOffset += windowWidth[i - 1] + getEdgeWidth(windowEdge[i * 2 - 1]) + getEdgeWidth(windowEdge[i * 2]);
                            if(withTBar)
                            {
                                for (int j = 0; j < tbarPos.Length; j++)
                                {
                                    //计算带T柱后与原点的偏移与实际x轴唯一的差值
                                    if (Math.Abs(xOffset + getEdgeWidth(windowEdge[i * 2 + 1]) - (tbarPos[j] - (tbarMinWidth / 2) - windowGap - lboardLHeight2 - getEdgeWidth(windowEdge[0]))) < ɛ)
                                    {
                                        xOffset += tbarMinWidth + 2 * windowGap;
                                    }
                                }
                            }
                            else
                            {
                                xOffset += windowGap;
                            }
                        }
                        pos = 1;
                        //画上板             
                        edgeStartPoints = DrawSingleBoard(new Point(startPoint.getX() + xOffset,startPoint.getY(),startPoint.getZ()), 1, pos,i);
                        edge = modelSpace.AddPolyline(edgeStartPoints);
                        edge.Closed = true;
                        previewImg.AddPolyLine(edgeStartPoints);
                        //画下板
                        edgeEndPoints = DrawSingleBoard(new Point(startPoint.getX() + xOffset, startPoint.getY() - yOffset, startPoint.getZ()), 1, pos,i);
                        edge = modelSpace.AddPolyline(edgeEndPoints);
                        edge.Closed = true;
                        previewImg.AddPolyLine(edgeEndPoints);
                    }
                    
                    break;
                case 2:
                    //画上板
                    edgeStartPoints = DrawSingleBoard(startPoint, 2, 1);
                    edge = modelSpace.AddPolyline(edgeStartPoints);
                    edge.Closed = true;
                    previewImg.AddPolyLine(edgeStartPoints);
                    //画下板
                    xOffset = lowerBoardHeight;
                    yOffset = hidePlainEdgeLength;
                    startPoint = new Point(startPoint.getX() + xOffset, startPoint.getY() - yOffset, startPoint.getZ());
                    edgeEndPoints = DrawSingleBoard(startPoint, 2, -1);
                    edge1 = modelSpace.AddPolyline(edgeEndPoints);
                    edge1.Closed = true;
                    previewImg.AddPolyLine(edgeEndPoints);
                    //画线
                    edgeStartPoints = new double[] { startPoint.getX(), startPoint.getY(), startPoint.getZ() };
                    edgeEndPoints = new double[] { startPoint.getX(), startPoint.getY() + yOffset, startPoint.getZ() };
                    modelSpace.AddLine(edgeStartPoints, edgeEndPoints);
                    previewImg.AddLine(edgeStartPoints, edgeEndPoints);

                    //尺寸标注
                    textPos = new double[] { startPoint.getX() + 25, (startPoint.getY() + startPoint.getY() - upperBoardWidth + 2 * yOffset) / 2, 0 };
                    AcadDimRotated dimRoated1 = modelSpace.AddDimRotated(new double[] { startPoint.getX(), startPoint.getY() + yOffset, startPoint.getZ() }, new double[] { startPoint.getX(), startPoint.getY() + yOffset - upperBoardWidth, startPoint.getZ() }, textPos, -Math.PI / 2);
                    dimRoated1.TextHeight = 10;
                    dimRoated1.Update();

                    textPos = new double[] { startPoint.getX() + 45, (startPoint.getY() + startPoint.getY() + yOffset) / 2, 0 };
                    AcadDimRotated dimRoated2 = modelSpace.AddDimRotated(new double[] { startPoint.getX(), startPoint.getY() + yOffset, startPoint.getZ() }, new double[] { startPoint.getX(), startPoint.getY(), startPoint.getZ() }, textPos, -Math.PI / 2);
                    dimRoated2.TextHeight = 10;
                    dimRoated2.Update();
                    break;
                default:
                    break;
            }
        }
        
        //画叶片
        public void DrawLeaf(Point startPoint, int view,bool withTBar)
        {
            double centerX, centerY, centerZ, mainAxisX, mainAxisY, subAxisX, subAxisY;
            double[] edgeStartPoints, edgeMidPoints, edgeEndPoints, textPos;
            int singleBladeNum = (bladeNum / windowNum);
            //double singleBladeWidth = (hidePlainEdgeLength - (upperBoardWidth + lowerBoardWidth - (boardSlotDept * 2))) / singleBladeNum;
            double singleBladeWidth = (hidePlainEdgeLength - (upperBoardWidth + lowerBoardWidth)) / singleBladeNum;
            double angle = Math.Asin(upperBoardHeight / bladeWidth) * 180 / Math.PI;

            double singleBladeHeight = bladeHeight * Math.Cos(angle);
            //长短轴比率
            double ratio = bladeHeight / bladeWidth;
            //初始化中心坐标
            centerX = startPoint.getX() + upperBoardHeight / 2.0;
            centerY = startPoint.getY() - (upperBoardWidth - boardSlotDept) - (singleBladeWidth / 2.0);
            centerZ = startPoint.getZ();
            int pos = 1;
            double xOffset = 0, yOffset = 0;

            AcadPolyline edge, edge1, edge2;
            AcadEllipse ellipse;
            switch (view)
            {
                case 0:
                    break;
                case 1:
                    xOffset = 0;
                    for (int i = 0;i < windowNum;i++)
                    {
                        pos = Convert.ToInt16(Math.Pow(-1, Convert.ToDouble(i)));
                        if (i > 0)
                        {
                            xOffset += windowWidth[i - 1] + getEdgeWidth(windowEdge[i * 2 - 1]) + getEdgeWidth(windowEdge[i * 2]);
                            if (withTBar)
                            {
                                for (int j = 0; j < tbarPos.Length; j++)
                                {
                                    //计算带T柱后与原点的偏移与实际x轴唯一的差值
                                    if (Math.Abs(xOffset + getEdgeWidth(windowEdge[i * 2 + 1]) - (tbarPos[j] - (tbarMinWidth / 2) - windowGap - lboardLHeight2 - getEdgeWidth(windowEdge[0]))) < ɛ)
                                    {
                                        xOffset += tbarMinWidth + 2 * windowGap;
                                    }
                                }
                            }
                            else
                            {
                                xOffset += windowGap;
                            }
                        }
                        pos = 1;
                        for (int j = 0; j < singleBladeNum; j++)
                        {
                            edgeStartPoints = DrawSingleLeaf(new Point(startPoint.getX() + xOffset, startPoint.getY() - j * singleBladeWidth, startPoint.getZ()), 1, pos ,i);
                            edge = modelSpace.AddPolyline(edgeStartPoints);
                            edge.Closed = true;
                            previewImg.AddPolyLine(edgeStartPoints);
                        }
                    }
                    DrawWindowPart(startPoint, 1, singleBladeWidth);
                    break;
                case 2:
                    singleBladeWidth = bladeWidth - 24.5;
                    yOffset = upperBoardWidth + (singleBladeWidth / 2);
                    centerY = startPoint.getY() - yOffset;

                    for (int i = 0; i < singleBladeNum; i++)
                    {
                        //中心点
                        edgeStartPoints = new double[] { centerX, centerY - i * singleBladeWidth, centerZ };
                        edgeMidPoints = new double[] { (bladeWidth / 2), (bladeHeight / 2), centerZ };
                        //长轴半径长，短轴半径长
                        edgeEndPoints = new double[] {
                                bladeWidth / 2.0,centerZ, centerZ
                        };
                        //Console.WriteLine(angle);
                        ellipse = modelSpace.AddEllipse(edgeStartPoints, edgeEndPoints, ratio);
                        ellipse.Rotate(edgeStartPoints, (90 - angle) * Math.PI / 180);
                        previewImg.AddEllipse(edgeMidPoints, edgeEndPoints, edgeStartPoints, bladeWidth, bladeHeight, angle);
                        //centerY -= i * singleBladeWidth;
                    }

                    //尺寸标注
                    //yOffset = hidePlainEdgeLength;
                    xOffset = upperBoardHeight;

                    textPos = new double[] { startPoint.getX() + upperBoardHeight + 40, (centerY + yOffset + centerY) / 2, 0 };
                    AcadDimRotated dimRotated1 = modelSpace.AddDimRotated(new double[] { startPoint.getX() + upperBoardHeight, centerY, startPoint.getZ() }, new double[] { startPoint.getX() + upperBoardHeight, centerY + yOffset, startPoint.getZ() }, textPos, -Math.PI / 2);
                    dimRotated1.TextHeight = 10;
                    dimRotated1.Update();
                    AcadDimOrdinate dimOrd = modelSpace.AddDimOrdinate(new double[] { centerX, centerY, centerZ }, new double[] { centerX - 45, centerY - singleBladeWidth, centerZ }, 0);
                    dimOrd.TextOverride = " 叶片 * " + singleBladeNum.ToString();
                    dimOrd.TextHeight = 10;
                    dimOrd.Update();
                    break;
                default:
                    break;
            }
        }

        public void DrawHinge(Point startPoint, int view,int windowIdx,int pos)
        {
            double[] edgeStartPoints, edgeEndPoints, edgeStartPoints1, edgeEndPoints1, edgeStartPoints2, edgeEndPoints2, textPos, textPos1, textPos2;
            AcadPolyline edge, edge1, edge2, edge3, edge4, edge5;
            switch (view)
            {
                case 0:
                    break;
                case 1:
                    if (windowNum == 1)
                    {
                        startPoint = new Point(startPoint.getX(), startPoint.getY() - (hingeMiddleDis[windowIdx] - (hingeHeight / 2)), startPoint.getZ());
                        edgeStartPoints = DrawSingleHinge(startPoint, 1, pos);
                        edge = modelSpace.AddPolyline(edgeStartPoints);
                        edge.Closed = true;
                        previewImg.AddPolyLine(edgeStartPoints);
                        startPoint = new Point(startPoint.getX(), startPoint.getY() - (hingeMiddleDis[windowIdx] + (hingeHeight / 2)), startPoint.getZ());
                        edgeEndPoints = DrawSingleHinge(startPoint, 1, pos);
                        edge1 = modelSpace.AddPolyline(edgeEndPoints);
                        edge1.Closed = true;
                        previewImg.AddPolyLine(edgeEndPoints);
                        //窗户尺寸标注
                        textPos = new double[] { (edgeStartPoints[0] + edgeEndPoints[0]) / 2, edgeStartPoints[1] + 10, 0 };
                        AcadDimAligned aligned1 = modelSpace.AddDimAligned(new double[] { edgeStartPoints[0], edgeStartPoints[1], edgeStartPoints[2] }, new double[] { edgeStartPoints[3], edgeStartPoints[4], edgeStartPoints[5] }, textPos);
                        aligned1.TextHeight = 10;
                        aligned1.Update();
                        textPos1 = new double[] { edgeEndPoints[3] - 10, (edgeStartPoints[4] + edgeEndPoints[7]) / 2, 0 };
                        AcadDimAligned aligned2 = modelSpace.AddDimAligned(new double[] { edgeStartPoints[3], edgeStartPoints[4], edgeStartPoints[5] }, new double[] { edgeStartPoints[6], edgeStartPoints[7], edgeStartPoints[8] }, textPos1);
                        aligned2.TextHeight = 10;
                        aligned2.Update();
                    }
                    break;
                case 2:
                    break;
                default:
                    break;
            }
        }

        //画L框单体
        public double[] DrawDoubleLSlot(Point startPoint, int view, int pos)
        {
            double[] points;
            switch (view)
            {
                case 0:
                    points = new double[]{
                        startPoint.getX(),startPoint.getY(),startPoint.getZ(),
                        startPoint.getX() + (double)pos * upperLBoardWidth,startPoint.getY(),startPoint.getZ(),//2
                        startPoint.getX() + (double)pos * upperLBoardWidth,startPoint.getY() - (lboardLHeight - lboardSlotWidth) / 2.0,startPoint.getZ(), //3
                        startPoint.getX() + (double)pos * upperLBoardWidth - ((double)pos * lboardSlotDept),startPoint.getY() - (lboardLHeight - lboardSlotWidth) / 2.0,startPoint.getZ(), //4
                        startPoint.getX() + (double)pos * upperLBoardWidth - ((double)pos * lboardSlotDept),startPoint.getY() - (lboardLHeight - lboardSlotWidth) / 2.0 - lboardSlotWidth,startPoint.getZ(), //5
                        startPoint.getX() + (double)pos * upperLBoardWidth,startPoint.getY() - (lboardLHeight - lboardSlotWidth) / 2.0 - lboardSlotWidth,startPoint.getZ(),//6
                        startPoint.getX() + (double)pos * upperLBoardWidth,startPoint.getY() - lboardLHeight,startPoint.getZ(),//7
                        startPoint.getX() + (double)pos * lboardLHeight2,startPoint.getY() - lboardLHeight ,startPoint.getZ(),//8
                        startPoint.getX() + (double)pos * lboardLHeight2,startPoint.getY() - upperLBoardHeight ,startPoint.getZ(),//9
                        startPoint.getX() ,startPoint.getY() - upperLBoardHeight ,startPoint.getZ(),//10
                     };
                    return points;
                case 1:
                    points = new double[] { };
                    return points;
                case 2:
                    if (windowNum <= 1)
                    {
                        points = new double[] {
                             startPoint.getX(),startPoint.getY(),startPoint.getZ(), //1
                             startPoint.getX() + upperLBoardHeight,startPoint.getY(),startPoint.getZ(),//2
                             startPoint.getX() + upperLBoardHeight,startPoint.getY() - ((lboardLHeight2 - lboardSlotWidth) / 2.0),startPoint.getZ(),//3
                             startPoint.getX() + upperLBoardHeight - lboardSlotDept,startPoint.getY() - ((lboardLHeight2 - lboardSlotWidth) / 2.0),startPoint.getZ(),//4

                             startPoint.getX() + upperLBoardHeight - lboardSlotDept,startPoint.getY() - (((lboardLHeight2 - lboardSlotWidth) / 2.0) + lboardSlotWidth),startPoint.getZ(),//5
                             startPoint.getX() + upperLBoardHeight ,startPoint.getY() - (((lboardLHeight2 - lboardSlotWidth) / 2.0) + lboardSlotWidth),startPoint.getZ(),//6
                             startPoint.getX() + upperLBoardHeight ,startPoint.getY() - lboardLHeight2,startPoint.getZ(),//7

                             startPoint.getX() + lboardLHeight ,startPoint.getY() - lboardLHeight2,startPoint.getZ(),//8
                             startPoint.getX() + lboardLHeight ,startPoint.getY() - upperLBoardWidth,startPoint.getZ(),//9

                             startPoint.getX() + lboardSlotWidth + ((lboardLHeight - lboardSlotWidth) / 2.0) ,startPoint.getY() - upperLBoardWidth,startPoint.getZ(),//10
                             startPoint.getX() + lboardSlotWidth + ((lboardLHeight - lboardSlotWidth) / 2.0) ,startPoint.getY() - (upperLBoardWidth - lboardSlotDept),startPoint.getZ(),//11

                             startPoint.getX() + ((lboardLHeight - lboardSlotWidth) / 2.0) ,startPoint.getY() - (upperLBoardWidth - lboardSlotDept),startPoint.getZ(),//12
                             startPoint.getX() + ((lboardLHeight - lboardSlotWidth) / 2.0) ,startPoint.getY() - upperLBoardWidth,startPoint.getZ(),//13
                             startPoint.getX(),startPoint.getY() - upperLBoardWidth,startPoint.getZ()//14
                       };
                    }
                    else
                    {
                        points = new double[] {
                            startPoint.getX(),startPoint.getY(),startPoint.getZ(), //1
                            startPoint.getX() + upperLBoardHeight,startPoint.getY(),startPoint.getZ(),//2
                            startPoint.getX() + upperLBoardHeight,startPoint.getY() - (double)pos * lboardLHeight2,startPoint.getZ(),//3
                            startPoint.getX() + lboardLHeight,startPoint.getY() - (double)pos *  lboardLHeight2,startPoint.getZ(),//4
                            startPoint.getX() + lboardLHeight,startPoint.getY()  - (double)pos *  upperLBoardWidth,startPoint.getZ(),//5
                            startPoint.getX() + ((lboardLHeight + lboardSlotWidth) / 2.0),startPoint.getY() - (double)pos *  upperLBoardWidth,startPoint.getZ(),//6
                            startPoint.getX() + ((lboardLHeight + lboardSlotWidth) / 2.0) ,startPoint.getY() - (double)pos *  (upperLBoardWidth - lboardSlotDept),startPoint.getZ(),//7
                            startPoint.getX() + ((lboardLHeight - lboardSlotWidth) / 2.0) ,startPoint.getY() - (double)pos *  (upperLBoardWidth - lboardSlotDept),startPoint.getZ(),//8
                            startPoint.getX() + ((lboardLHeight - lboardSlotWidth) / 2.0)  ,startPoint.getY() - (double)pos * upperLBoardWidth,startPoint.getZ(),//9
                            startPoint.getX() ,startPoint.getY() - (double)pos * upperLBoardWidth,startPoint.getZ()
                        };
                    }
                    return points;
                default:
                    points = new double[] { };
                    return points;
            }

        }

        //画T柱单体
        public double[] DrawTBar(Point startPoint, int view)
        {
            double[] points;
            if (view == 0)
            {
                points = new double[] {startPoint.getX(),startPoint.getY(),startPoint.getZ(),
                startPoint.getX() + tbarMaxWidth,startPoint.getY(),startPoint.getZ(),
                startPoint.getX() + tbarMaxWidth,startPoint.getY() - (tbarHeight - tbarCornerHeight),startPoint.getZ(),
                startPoint.getX() + tbarMinWidth + ((tbarMaxWidth - tbarMinWidth) / 2),startPoint.getY() - (tbarHeight - tbarCornerHeight),startPoint.getZ(),
                startPoint.getX() + tbarMinWidth + ((tbarMaxWidth - tbarMinWidth) / 2),startPoint.getY() - tbarHeight,startPoint.getZ(),
                startPoint.getX()  + ((tbarMaxWidth - tbarMinWidth) / 2),startPoint.getY() - tbarHeight,startPoint.getZ(),
                startPoint.getX()  + ((tbarMaxWidth - tbarMinWidth) / 2),startPoint.getY() - (tbarHeight - tbarCornerHeight),startPoint.getZ(),
                startPoint.getX(),startPoint.getY() - (tbarHeight - tbarCornerHeight),startPoint.getZ(),
                };
                return points;
            }
            else if (view == 1)
            {
                points = new double[] {startPoint.getX(),startPoint.getY(),startPoint.getZ(),
                    startPoint.getX() + tbarMinWidth,startPoint.getY(),startPoint.getZ(),
                    startPoint.getX() + tbarMinWidth,startPoint.getY() - tbarLength,startPoint.getZ(),
                    startPoint.getX(),startPoint.getY() - tbarLength,startPoint.getZ(),
                };
                return points;
            }
            else
            {
                points = new double[] { };
                return points;
            }
        }

        //type-0-隐形平门边 1-平门边,2-隐形平盖片门边,3-平盖片门边
        public double[] DrawSingleEdge(Point startPoint, int view, int pos, int type)
        {
            double[] points;
            switch (view)
            {
                case 0:
                    switch(type)
                    {
                        case 0:
                            points = new double[] {
                                startPoint.getX(),startPoint.getY(),startPoint.getZ(), //1
                                startPoint.getX() + (double)pos * hidePlainEdgeWidth,startPoint.getY(),startPoint.getZ(), //2
                                startPoint.getX() + (double)pos * hidePlainEdgeWidth,startPoint.getY() - (hidePlainEdgeHeight- hidePlainEdgeSlotWidth) / 2.0,startPoint.getZ(), //3
                                startPoint.getX()  + (double)pos * (hidePlainEdgeWidth - hidePlainEdgeSlotDept),startPoint.getY() - (hidePlainEdgeHeight - hidePlainEdgeSlotWidth) / 2.0,startPoint.getZ(), //4
                                startPoint.getX()  + (double)pos * (hidePlainEdgeWidth - hidePlainEdgeSlotDept),startPoint.getY() - (hidePlainEdgeHeight - hidePlainEdgeSlotWidth) / 2.0 - hidePlainEdgeSlotWidth,startPoint.getZ(), //5
                                startPoint.getX()  + (double)pos * hidePlainEdgeWidth,startPoint.getY() - (hidePlainEdgeHeight- hidePlainEdgeSlotWidth) / 2.0 - hidePlainEdgeSlotWidth,startPoint.getZ(), //6
                                startPoint.getX()  + (double)pos * hidePlainEdgeWidth,startPoint.getY() - hidePlainEdgeHeight,startPoint.getZ(), //7
                                startPoint.getX(),startPoint.getY() - hidePlainEdgeHeight,startPoint.getZ(), //8
                            };
                            break;
                        case 1:
                            points = new double[] {
                                startPoint.getX() ,startPoint.getY(),startPoint.getZ(),
                                startPoint.getX() + (double)pos * plainEdgeWidth,startPoint.getY(),startPoint.getZ(),
                                startPoint.getX() + (double)pos * plainEdgeWidth,startPoint.getY() - plainEdgeHeight,startPoint.getZ(),
                                startPoint.getX(), startPoint.getY() - plainEdgeHeight,startPoint.getZ(),
                            };
                            break;
                        case 2:
                            points = new double[] {
                                startPoint.getX(),startPoint.getY(),startPoint.getZ(), //1
                                startPoint.getX() + (double)pos * hideCoverEdgeWidth,startPoint.getY(),startPoint.getZ(),//2
                                startPoint.getX() + (double)pos * hideCoverEdgeWidth,startPoint.getY() - (hideCoverEdgeHeight-hidePlainEdgeSlotWidth) / 2.0,startPoint.getZ(), //3
                                startPoint.getX() + (double)pos * (hideCoverEdgeWidth - hidePlainEdgeSlotDept),startPoint.getY() - (hideCoverEdgeHeight-hidePlainEdgeSlotWidth) / 2.0,startPoint.getZ(), //4
                                startPoint.getX() + (double)pos * (hideCoverEdgeWidth - hidePlainEdgeSlotDept),startPoint.getY() -  (hideCoverEdgeHeight- hidePlainEdgeSlotWidth) / 2.0 - hidePlainEdgeSlotWidth,startPoint.getZ(), //5
                                startPoint.getX() + (double)pos * hideCoverEdgeWidth,startPoint.getY() -  (hideCoverEdgeHeight-hidePlainEdgeSlotWidth) / 2.0 - hidePlainEdgeSlotWidth,startPoint.getZ(),//6
                                startPoint.getX() + (double)pos * hideCoverEdgeWidth,startPoint.getY() - hideCoverEdgeHeight,startPoint.getZ(),//7
                                startPoint.getX() + (double)pos * (HideCoverEdgerCoverWidth - (hideCoverEdgeCoverMaxWidth - hideCoverEdgeWidth)) ,startPoint.getY() - hideCoverEdgeHeight ,startPoint.getZ(),//8
                                startPoint.getX() + (double)pos * (HideCoverEdgerCoverWidth - (hideCoverEdgeCoverMaxWidth - hideCoverEdgeWidth)) ,startPoint.getY() - hideCoverEdgeCoverMaxHeight ,startPoint.getZ(),//9
                                startPoint.getX() - (double)pos * (hideCoverEdgeCoverMaxWidth - hideCoverEdgeWidth) ,startPoint.getY() - hideCoverEdgeCoverMaxHeight ,startPoint.getZ(),//10
                                startPoint.getX() - (double)pos * (hideCoverEdgeCoverMaxWidth - hideCoverEdgeWidth),startPoint.getY() - hideCoverEdgeHeight ,startPoint.getZ(),//11
                                startPoint.getX(),startPoint.getY() - hideCoverEdgeHeight ,startPoint.getZ()//12
                            };
                            break;
                        case 3:
                            points = new double[] {
                                startPoint.getX(),startPoint.getY(),startPoint.getZ(), //1
                                startPoint.getX()  + (double)pos * plainCoverEdgeWidth,startPoint.getY(),startPoint.getZ(), //2
                                startPoint.getX()  + (double)pos * plainCoverEdgeWidth,startPoint.getY() - plainCoverEdgeHeight,startPoint.getZ(), //3

                                startPoint.getX()  + (double)pos * (plainCoverEdgeWidth - (plainCoverEdgeCoverMaxWidth - PlainCoverEdgerCoverWidth)),startPoint.getY() - plainCoverEdgeHeight,startPoint.getZ(), //4
                                startPoint.getX()  + (double)pos * (plainCoverEdgeWidth - (plainCoverEdgeCoverMaxWidth - PlainCoverEdgerCoverWidth)),startPoint.getY() - plainCoverEdgeCoverMaxHeight,startPoint.getZ(), //5

                                startPoint.getX()  + (double)pos * (plainCoverEdgeWidth-plainCoverEdgeCoverMaxWidth),startPoint.getY() - plainCoverEdgeCoverMaxHeight,startPoint.getZ(), //6
                                startPoint.getX()  + (double)pos * (plainCoverEdgeWidth-plainCoverEdgeCoverMaxWidth),startPoint.getY() - plainCoverEdgeHeight,startPoint.getZ(), //7
                                startPoint.getX() ,startPoint.getY() - plainCoverEdgeHeight,startPoint.getZ() //8
                                };
                            break;
                        default:
                            points = new double[] { };
                            break;
                    }
                    return points;
                case 1:
                    switch(type)
                    {
                        case 0:
                            points = new double[] {
                                startPoint.getX(),startPoint.getY(),startPoint.getZ(), //1
                                startPoint.getX() + (double)pos * hidePlainEdgeWidth,startPoint.getY(),startPoint.getZ(), //2
                                startPoint.getX() + (double)pos *hidePlainEdgeWidth,startPoint.getY() - hidePlainEdgeLength,startPoint.getZ(), //3
                                startPoint.getX(),startPoint.getY() - hidePlainEdgeLength,startPoint.getZ(), //4
                            };
                            break;
                        case 1:
                            points = new double[] {
                                startPoint.getX(),startPoint.getY(),startPoint.getZ(), //1
                                startPoint.getX() + (double)pos * plainEdgeWidth,startPoint.getY(),startPoint.getZ(), //2
                                startPoint.getX() + (double)pos * plainEdgeWidth,startPoint.getY() - plainEdgeLength,startPoint.getZ(), //3
                                startPoint.getX(),startPoint.getY() - plainEdgeLength,startPoint.getZ(), //4
                            };
                            break;
                        case 2:
                            points = new double[] {
                                startPoint.getX(),startPoint.getY(),startPoint.getZ(), //1
                                startPoint.getX() + (double)pos * hidePlainEdgeWidth,startPoint.getY(),startPoint.getZ(), //2
                                startPoint.getX() + (double)pos * hidePlainEdgeWidth,startPoint.getY() - hideCoverEdgeLength,startPoint.getZ(), //3
                                startPoint.getX(),startPoint.getY() - hideCoverEdgeLength,startPoint.getZ(), //4
                            };
                            break;
                        case 3:
                            points = new double[] {
                                startPoint.getX(),startPoint.getY(),startPoint.getZ(), //1
                                startPoint.getX() + (double)pos * plainCoverEdgeWidth,startPoint.getY(),startPoint.getZ(), //2
                                startPoint.getX() + (double)pos * plainCoverEdgeWidth,startPoint.getY() - plainCoverEdgeLength,startPoint.getZ(), //3
                                startPoint.getX(),startPoint.getY() - plainCoverEdgeLength,startPoint.getZ(), //4
                            };
                            break;
                        default:
                            points = new double[] { };
                            break;
                    }
                    return points;
                case 2:
                    points = new double[] { };
                    return points;
                default:
                    points = new double[] { };
                    return points;
            }
        }

        //windowIdx-窗口序号
        public double[] DrawSingleBoard(Point startPoint, int view, int pos, int windowIdx = 0)
        {
            double[] points;
            switch (view)
            {
                case 0:
                    points = new double[] { };
                    return points;
                case 1:
                    points = new double[] {
                        startPoint.getX(),startPoint.getY(),startPoint.getZ(),
                        startPoint.getX() + windowWidth[windowIdx],startPoint.getY(),startPoint.getZ(),
                        startPoint.getX() + windowWidth[windowIdx],startPoint.getY() - boardWidth,startPoint.getZ(),
                        startPoint.getX(),startPoint.getY() - boardWidth,startPoint.getZ(),
                    };
                    return points;
                case 2:
                    points = new double[] {
                        startPoint.getX(),startPoint.getY(),startPoint.getZ(),
                        startPoint.getX() + (double)pos * boardHeight,startPoint.getY(),startPoint.getZ(),
                        startPoint.getX() + (double)pos * boardHeight,startPoint.getY() - (double)pos * (boardWidth - boardSlotWidth) ,startPoint.getZ(),
                        startPoint.getX() + (double)pos * (boardHeight - boardSlotDept),startPoint.getY() - (double)pos * (boardWidth - boardSlotWidth) ,startPoint.getZ(),
                        startPoint.getX() + (double)pos * (boardHeight - boardSlotDept),startPoint.getY() - (double)pos * boardWidth ,startPoint.getZ(),
                        startPoint.getX(), startPoint.getY() - (double)pos * boardWidth ,startPoint.getZ()
                    };
                    return points;
                default:
                    points = new double[] { };
                    return points;
            }
        }

        public double[] DrawSingleLeaf(Point startPoint, int view, int pos, int windowIdx)
        {
            int singleBladeNum = (bladeNum / windowNum);
            double singleBladeWidth = (hidePlainEdgeLength - (upperBoardWidth + lowerBoardWidth)) / singleBladeNum;

            double[] points;
            switch (view)
            {
                case 0:
                    points = new double[] { };
                    return points;
                case 1:
                    points = new double[] {
                        startPoint.getX(),startPoint.getY(),startPoint.getZ(),
                        startPoint.getX() + windowWidth[windowIdx],startPoint.getY(),startPoint.getZ(),
                        startPoint.getX() + windowWidth[windowIdx],startPoint.getY() - singleBladeWidth,startPoint.getZ(),
                        startPoint.getX(),startPoint.getY() - singleBladeWidth,startPoint.getZ(),
                    };
                    return points;
                case 2:
                    points = new double[] {

                    };
                    return points;
                default:
                    points = new double[] { };
                    return points;
            }
        }

        public double[] DrawSingleHinge(Point startPoint, int view, int pos)
        {
            double[] points;
            switch (view)
            {
                case 0:
                    points = new double[] { };
                    return points;
                case 1:
                    points = new double[] {
                            startPoint.getX() ,startPoint.getY(),startPoint.getZ(),
                            startPoint.getX() + (double)pos * hingeWidth,startPoint.getY(),startPoint.getZ(),
                            startPoint.getX() + (double)pos * hingeWidth,startPoint.getY() - hingeHeight,startPoint.getZ(),
                            startPoint.getX(), startPoint.getY() - hingeHeight,startPoint.getZ(),
                    };

                    return points;
                case 2:
                    points = new double[] { };
                    return points;
                default:
                    points = new double[] { };
                    return points;
            }
        }

        public void DrawWindowPart(Point startPoint, int view, double singleBladeWidth)
        {
            double[] partWindowUp, partWindowLow, partWindowUp1, partWindowLow1, partTextPos, textPos;
            double windowUpperArea, windowLowerArea;
            double partXOffset = 30;
            double xOffset = 0;
            if (view == 1)
            {
                for(int i =0;i < windowNum;i++)
                {
                    if(isWindowsPart[i] != 0)
                    {
                        windowUpperArea = wndUpperArea[i];
                        windowLowerArea = wndLowerArea[i];
                        //上
                        partWindowUp = new double[] { startPoint.getX() + xOffset +partXOffset, startPoint.getY() - singleBladeWidth, startPoint.getZ() };
                        partWindowLow = new double[] { startPoint.getX() + xOffset + partXOffset, startPoint.getY() - windowUpperArea * singleBladeWidth, startPoint.getZ() };
                        modelSpace.AddLine(partWindowUp, partWindowLow);
                        partTextPos = new double[] { startPoint.getX() + xOffset + partXOffset + 10, startPoint.getY() - (windowUpperArea / 2) * singleBladeWidth, startPoint.getZ() };
                        modelSpace.AddText(windowUpperArea.ToString(), partTextPos, singleBladeWidth);
                        previewImg.AddLine(partWindowUp, partWindowLow);

                        textPos = new double[] { partWindowUp[0] - 10, (partWindowUp[0] + partWindowLow[0]) / 2, 0 };
                        AcadDimRotated aligned1 = modelSpace.AddDimRotated(new double[] { partWindowUp[0], partWindowUp[1], partWindowUp[2] }, new double[] { partWindowLow[0], partWindowLow[1], partWindowLow[2] }, textPos, Math.PI / 2);
                        aligned1.TextHeight = 10;
                        aligned1.Update();
                        previewImg.AddText(windowUpperArea.ToString(), partTextPos);

                        //下

                        partWindowUp1 = new double[] { startPoint.getX() + xOffset + partXOffset, startPoint.getY() - (windowUpperArea + 1) * singleBladeWidth, startPoint.getZ() };
                        partWindowLow1 = new double[] { startPoint.getX() + xOffset + partXOffset, startPoint.getY() - (windowUpperArea + windowLowerArea) * singleBladeWidth, startPoint.getZ() };
                        modelSpace.AddLine(partWindowUp1, partWindowLow1);
                        partTextPos = new double[] { startPoint.getX() + xOffset + partXOffset + 10, startPoint.getY() - (windowUpperArea + (windowLowerArea / 2)) * singleBladeWidth, startPoint.getZ() };
                        modelSpace.AddText(windowLowerArea.ToString(), partTextPos, singleBladeWidth);
                        previewImg.AddLine(partWindowUp1, partWindowLow1);

                        textPos = new double[] { partWindowUp1[0] - 10, (partWindowUp1[0] + partWindowLow1[0]) / 2, 0 };
                        AcadDimRotated aligned2 = modelSpace.AddDimRotated(new double[] { partWindowUp1[0], partWindowUp1[1], partWindowUp1[2] }, new double[] { partWindowLow1[0], partWindowLow1[1], partWindowLow1[2] }, textPos, Math.PI / 2);
                        aligned2.TextHeight = 10;
                        aligned2.Update();
                        previewImg.AddText(windowLowerArea.ToString(), partTextPos);
                    }
                    if(i >=0 && i < windowNum - 1)
                    {
                        xOffset += windowWidth[i] + (i > tbarPos.Length ? windowGap : 2 * windowGap + tbarMinWidth) + (getEdgeWidth(windowEdge[(i + 1) * 2]) + getEdgeWidth(windowEdge[(i + 1) * 2 + 1]));
                    }
                    else
                    {
                        xOffset = 0;
                    }


                }





            }
        }

        public double getEdgeWidth(int type)
        {
            double edgeWidth = 0;
            switch(type)
            {
                case 0:
                    edgeWidth = hidePlainEdgeWidth;
                    break;
                case 1:
                    edgeWidth = plainEdgeWidth;
                    break;
                case 2:
                    edgeWidth = hideCoverEdgeWidth;
                    break;
                case 3:
                    edgeWidth = plainCoverEdgeWidth;
                    break;
            }

            return edgeWidth;
        }
    }
}
